import pygame
import sys
import random as r

pygame.init()

size=width,height = 600,600
turtle_HP=1000
turtle_speed=[-4,-2]
fish_speed=[-2,1]
js_speed=[300,300]

bg=(255,255,255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('乌龟吃小鱼')

turtle = pygame.image.load('乌龟.jpg')
fish = pygame.image.load('金鱼.jpg')
js = pygame.image.load('结束.jpg')

turtle_position=turtle.get_rect()
fish_position=fish.get_rect()
#js_position=js.get_rect()
js_position=pygame.Rect(300,300,132,161)

while True :
    
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    turtle_position = turtle_position.move(turtle_speed)
    fish_position = fish_position.move(fish_speed)
    if turtle_HP > 0 :
        turtle_HP-=1
        if turtle_position.left < 0 or turtle_position.right > width:
            turtle = pygame.transform.flip(turtle,True,False)
            turtle_speed[0] = -turtle_speed[0]
        if turtle_position.top < 0 or turtle_position.bottom > height:
            turtle_speed[1] = -turtle_speed[1]
    else :
        break
    if turtle_position == fish_position :
        turtle_HP+=20
    else:
        if fish_position.left < 0 or fish_position.right > width:
            fish = pygame.transform.flip(fish,True,False)
            fish_speed[0] = -fish_speed[0]
        if fish_position.top < 0 or fish_position.bottom > height:
            fish_speed[1] = -fish_speed[1]
        screen.blit(fish,fish_position)

    screen.fill(bg)
    screen.blit(turtle,turtle_position)
    pygame.display.flip()
    pygame.time.delay(10)
    #print(type(turtle_position))
    
screen.fill(bg)
screen.blit(js,js_position)
pygame.display.flip()
pygame.time.delay(10)

